package com.geek.gkpush.framework.event.core;

import com.geek.gkpush.framework.threadpool.executor.EagerExecutor;
import com.geek.gkpush.framework.threadpool.executor.EagerQueue;
import com.geek.gkpush.framework.threadpool.reject.AbortPolicyWrapper;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * <h1>默认的事件消息线程池配置类。</h1><br/>
 *
 * <h1><br/><a href="https://u.geekbang.org/subject/arch3/100614201">Java 业务架构实战营：https://u.geekbang.org/subject/arch3/100614201</a></h1><br/><h1><a href="https://gitee.com/ylimhhmily/BizArchPracticeCamp">Java 业务架构实战营代码地址：https://gitee.com/ylimhhmily/BizArchPracticeCamp</a></h1><br/><h1><a href="https://u.geekbang.org/subject/java4th/1001148?source=app_share">高级 Java 工程体系课 2023 版：https://u.geekbang.org/subject/java4th/1001148?source=app_share</a></h1><br/><h1><a href="https://time.geekbang.org/column/intro/100312101?tab=catalog">Dubbo 源码剖析与实战：https://time.geekbang.org/column/intro/100312101?tab=catalog</a></h1>
 *
 * @author hmilyylimh
 * ^_^
 * @version 0.0.1
 * ^_^
 * @date 2023/10/3 08:47
 */
@Configuration
public class EagerExecutorConfig {

    /**
     * <h2>获取默认的事件线程池。</h2>
     *
     * @return
     */
    @Bean(name = "defaultEventMsgExecutor")
    public EagerExecutor defaultEventMsgExecutor() {
        EagerQueue<Runnable> taskQueue = new EagerQueue<>(2048);

        EagerExecutor executor = new EagerExecutor(
                1,
                20,
                1,
                TimeUnit.MINUTES,
                taskQueue,
                new NamedThreadFactory("defaultEventMsgExecutor", true),
                new AbortPolicyWrapper("defaultEventMsgExecutor"));
        taskQueue.setExecutor(executor);

        return executor;
    }
}